class AceCameraIso extends GameCameraBase;

var float MinHeight, MaxHeight;

function OnBecomeActive( GameCameraBase OldCamera )
{
	super.OnBecomeActive( OldCamera );

	`log( Name @ "Become active" );
}

function OnBecomeInActive( GameCameraBase OldCamera )
{
	super.OnBecomeInActive( OldCamera );

	`log( Name @ "Become inactive" );
}

function float GetHeightBasedOnDistanceBetweenPlayer( AcePawn pawn )
{
	local Vector2D vin, vout;
	
	vin.X = 0.0f;
	vin.Y = pawn.LinkDistanceMax;

	vout.X = MinHeight;
	vout.Y = MaxHeight;

	return GetMappedRangeValue( vin, vout, pawn.LinkCurrentDistance );
}

simulated function UpdateCamera( Pawn P, GamePlayerCamera CameraActor, float DeltaTime, out TViewTarget OutVT )
{
	local CameraActor camera_actor;
	local Vector x, y, z, new_location, median_loc;
	local AcePawn ace_Pawn;
	//local Rotator new_rot;
	//local Vector dir_tilt;

	camera_actor = CameraActor( OutVT.Target );

	if ( camera_actor != None )
	{
		OutVT.POV.FOV = camera_actor.FOVAngle;
		OutVT.POV.Location = camera_actor.Location;
		OutVT.POV.Rotation = camera_actor.Rotation;
	}
	else
	{
		if( P == none )
			return;

		GetAxes( P.Rotation, x, y, z );
		OutVT.POV.FOV = CameraActor.DefaultFOV;

		ace_Pawn = AcePawn( P );

		if( ace_Pawn != none )
		{
			if( ace_Pawn.LinkPawn != none )
			{
				median_loc = ( ace_Pawn.Location + ace_Pawn.LinkPawn.Location ) / 2.0f;
				median_loc.Z = 0.0f;
				new_location =  median_loc;
				new_location.Z += GetHeightBasedOnDistanceBetweenPlayer( ace_Pawn );
			}
			else
			{
				new_location = ace_Pawn.Location;
				new_location.Z += 600.0f;
			}

			OutVt.POV.Location = new_location;
			OutVt.POV.Rotation = Rotator( Vect(0,0,-1) );

			/*
			if( !IsZero(ace_Pawn.Velocity) )
			{
				dir_tilt = ace_Pawn.Velocity;
				dir_tilt.Z = 0.0f;
				dir_tilt = Normal( dir_tilt );

				new_rot = Rotator( dir_tilt );

				OutVt.POV.Rotation = RLerp( new_rot, OutVt.POV.Rotation, 0.9f, true );
			}*/
		}
		else
		{
			`warn( Name @ "wrong pawn setup" @ P.Name @ "should be AcePawn" );
		}	
	}
}

DefaultProperties
{
	MinHeight = 500.0f
	MaxHeight = 900.0f
}